package lib.classes;

import java.util.Date;
import java.util.Hashtable;

import lib.Util;
import net.rim.blackberry.api.browser.URLEncodedPostData;
import net.rim.device.api.system.DeviceInfo;
import net.rim.device.api.system.EncodedImage;

public class Profile
{
	private int pin;
	private String gender, screenname, status;
	private Date dob;
	private String aboutme;
	private Location location;
	private boolean isPrivate;
	private EncodedImage image;
	//private boolean searchable;
	private boolean syncWithBBM;
	
	public Profile(int pin, Date dob, String screenName, String status, String aboutMe, String gender, String city, String state, String country, boolean syncWithBBM)
	{
		setPin(pin);
		setDOB(dob);
		setScreenname(screenName);
		setStatus(status);
		setGender(gender);
		location = new Location(country, state, city);
		setAboutme(aboutMe);
		isPrivate = false;
		this.setSyncWithBBM(syncWithBBM);
	}
	public int getPin()
	{
		return this.pin;
	}
	public void setPin(int pin)
	{
		this.pin = pin;
	}
	public void setGender(String gender) {
		this.gender = gender;
	}
	public String getGender() {
		return gender;
	}
	public void setAboutme(String aboutme) {
		this.aboutme = aboutme;
	}
	public String getAboutme() {
		return aboutme;
	}
	public void setScreenname(String screenname) {
		this.screenname = screenname;
	}
	public String getScreenname() {
		return screenname;
	}
	public Location getLocation() {
		return location;
	}
	public void setStatus(String status) {
		this.status = status;
	}
	public String getStatus() {
		return status;
	}
	public void setDOB(Date dob) {
		this.dob = dob;
	}
	public int getAge() {
		return Util.getAge(dob);
	}
	
	public Date getDOB()
	{
		return this.dob;
	}
	public void setPrivate(boolean isPrivate) {
		this.isPrivate = isPrivate;
	}
	public boolean isPrivate() {
		return isPrivate;
	}

	public void setImage(EncodedImage image) {
		this.image = image;
	}
	public EncodedImage getImage() {
		return image;
	}
	
	/**
	 * 
	 * @return URLEncodedPostData of the following:
	 * screenName, status, dob, aboutYou, gender, city, province, country, searchable
	 */
	public URLEncodedPostData getURLEncodedPostData()
	{
		URLEncodedPostData encPostData = new URLEncodedPostData("UTF-8", false);
		encPostData.append("pin", this.getPin()+"");
    	encPostData.append("screenName", getScreenname());
    	encPostData.append("status", getStatus());
    	encPostData.append("dob", getDOB().getTime()+"");
    	encPostData.append("aboutYou", getAboutme());
    	encPostData.append("gender", getGender());
    	encPostData.append("city", location.getCity());
    	encPostData.append("province", location.getProvince());
    	encPostData.append("country", location.getCountry());
    	encPostData.append("searchable", isPrivate==false? "true":"false");
    	    	
    	return encPostData;
    	
	}
	
	public Hashtable getHashtableData()
	{
		Hashtable params = new Hashtable();
		params.put("pin", this.getPin()+"");
		params.put("screenName", getScreenname());
		params.put("status", getStatus());
		params.put("dob", getDOB().getTime()+"");
    	params.put("aboutYou", getAboutme());
    	params.put("gender", getGender());
    	params.put("city", location.getCity());
    	params.put("province", location.getProvince());
    	params.put("country", location.getCountry());
    	params.put("searchable", isPrivate==false? "true":"false");
		return params;
	}
	
	public void setSyncWithBBM(boolean syncWithBBM) {
		this.syncWithBBM = syncWithBBM;
	}
	public boolean isSyncWithBBM() {
		return syncWithBBM;
	}
	
	public boolean canEdit()
	{
		return this.pin == DeviceInfo.getDeviceId();
	}
}
